package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.domain.db.UserInfo;
import com.tanhua.dubbo.mapper.UserInfoMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

/**
 * @author liuyp
 * @date 2021/01/26
 */
@Service
public class UserInfoApiImpl implements UserInfoApi {
    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public void save(UserInfo userInfo) {
        // userInfo.setCreated(new Date());
        // userInfo.setUpdated(new Date());
        userInfoMapper.insert(userInfo);
    }

    @Override
    public void update(UserInfo userInfo) {
        // userInfo.setUpdated(new Date());
        userInfoMapper.updateById(userInfo);
    }

    @Override
    public UserInfo findById(Long id) {
        return userInfoMapper.selectById(id);
    }

    @Override
    public IPage<UserInfo> findUserList(int page, int pagesize) {
        /**
         * 分页查询，必须要提供：分页信息 ==> 封装成Page对象，传递给MybatisPlus的selectPage方法
         *      1. 查询哪一页
         *      2. 查询多少条
         * 还需要提供一些条件：搜索条件  ==> 封装QueryWrapper，传递给MybatisPlus的selectPage方法
         */
        return userInfoMapper.selectPage(new Page<>(page, pagesize), null);
    }
}
